package cn.fresh.xuanyuan.module.product.dal.mysql.orchard;

import cn.fresh.xuanyuan.framework.common.pojo.PageParam;
import cn.fresh.xuanyuan.framework.common.pojo.PageResult;
import cn.fresh.xuanyuan.framework.mybatis.core.mapper.BaseMapperX;
import cn.fresh.xuanyuan.framework.mybatis.core.query.LambdaQueryWrapperX;
import cn.fresh.xuanyuan.module.product.dal.dataobject.orchard.OrchardDO;
import cn.fresh.xuanyuan.module.product.vo.orchard.OrchardRespVO;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import org.apache.commons.lang3.StringUtils;
import org.apache.ibatis.annotations.Mapper;

@Mapper
public interface OrchardMapper extends BaseMapperX<OrchardDO> {

    default PageResult<OrchardDO> getOrchardPage(String name, String phone, PageParam pageReq) {
        LambdaQueryWrapper<OrchardDO> queryWrapperX = new LambdaQueryWrapper<OrchardDO>()
                .orderByDesc(OrchardDO::getCreateTime);
        if(StringUtils.isNotBlank(name)) {
            queryWrapperX.like(OrchardDO::getName, name.trim());
        }
        if(StringUtils.isNotBlank(phone)) {
            queryWrapperX.eq(OrchardDO::getPhone, phone.trim());
        }
        return selectPage(pageReq, queryWrapperX);
    }
}
